#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@File    :   learntest.py
@Time    :   2024/11/25 19:51:18
@Author  :   xiangyu Chen
@Version :   1.0
@Contact :   yu112yu@sina.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@Desc    :   None
'''

import pytest
import sys


@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
def test_demo(x, y):
    print(x, y)


dict1 = [{"name": "杨过", "age": 18}, {"name": "小龙女", "age": 27}, {"name": "黄蓉", "age": 29}]


@pytest.mark.parametrize("dict1", dict1)
def test_demo(dict1):
    print(dict1.get('name'))


# 没有传ids的,默认用参数值
@pytest.mark.parametrize("x, y", [(0, 1), (2, 3), (4, 5)])
def test_demo01(x, y):
    pass


# 传入了ids的,使用ids中的名称
@pytest.mark.parametrize("x, y", [(0, 1), (2, 3), (4, 5)], ids=("第一次", "第二次", "第三次"))
def test_demo02(x, y):
    pass


if __name__ == '__main__':

    def return_selffunc(func):
        print("This's {}, used {}".format(sys._getframe().f_code.co_name, func.__name__))
        return func

    def return_otherfunc(func):
        print("This's {}, used {}".format(sys._getframe().f_code.co_name, func.__name__))

        def otherfunc():
            print("This's {}".format(sys._getframe().f_code.co_name))
            pass

        return otherfunc

    def decorator_basic(func):
        def wrapper(*args, **kwargs):
            # 在这里添加额外的功能
            print("Before calling the function. This's {}, used {}".format(sys._getframe().f_code.co_name, func.__name__))
            result = func(*args, **kwargs)
            print("After calling the function. This's {}, used {}".format(sys._getframe().f_code.co_name, func.__name__))
            return result

        return wrapper

    @decorator_basic
    @return_otherfunc
    @return_selffunc
    def b():
        print("b")

    b()
